package com.xbongbong.saas.help;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.domain.entity.PaasFormExplainEntity;
import com.xbongbong.paas.domain.entity.PaasProcessDataEntity;
import com.xbongbong.paas.domain.entity.ResultShowRuleEntity;
import com.xbongbong.paas.domain.entity.ext.ConditionsEntityExt;
import com.xbongbong.paas.domain.entity.ext.OptionalRangeEntity;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.domain.entity.ext.PaasFormEntityExt;
import com.xbongbong.paas.elasticsearch.util.EsHelper;
import com.xbongbong.paas.elasticsearch.util.EsUtil;
import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.enums.FlowStatusEnum;
import com.xbongbong.paas.enums.IndexTypeEnum;
import com.xbongbong.paas.enums.OptionalRangeEnum;
import com.xbongbong.paas.field.CustomRecheckRulePojo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.help.CommonHelp;
import com.xbongbong.paas.model.PaasFormExplainModel;
import com.xbongbong.paas.model.PaasFormModel;
import com.xbongbong.paas.model.ResultShowRuleModel;
import com.xbongbong.paas.pojo.ResultShowRulePojo;
import com.xbongbong.paas.pojo.dto.ProcessNodeTaskGetDTO;
import com.xbongbong.paas.pojo.vo.ProcessNodeTaskGetVO;
import com.xbongbong.paas.service.PaasProcessNodeTaskService;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.paas.toolbox.util.CollectionsUtil;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.paas.toolbox.wrap.UserVO;
import com.xbongbong.paas.util.ExplainUtil;
import com.xbongbong.pro.common.pojo.RepeatSearchFieldPojo;
import com.xbongbong.pro.common.pojo.SeniorCheckRepeatSearchPojo;
import com.xbongbong.pro.common.pojo.dto.CheckRepeatToolDTO;
import com.xbongbong.pro.common.pojo.dto.SeniorReCheckSearchDTO;
import com.xbongbong.pro.constant.CommonConstant;
import com.xbongbong.pro.constant.I18nStringConstant;
import com.xbongbong.pro.domain.entity.FormConfigEntity;
import com.xbongbong.pro.enums.PackageTypeEnum;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.recheck.pojo.RecheckAttrRulePojo;
import com.xbongbong.pro.recheck.pojo.RecheckFormRulePojo;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.domain.entity.PublicGroupEntity;
import com.xbongbong.saas.domain.entity.PublicGroupSeniorEntity;
import com.xbongbong.saas.domain.entity.RecheckingRuleEntity;
import com.xbongbong.saas.enums.RepeatTypeEnum;
import com.xbongbong.saas.enums.SeniorPublicGroupTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.ClueEnum;
import com.xbongbong.saas.enums.business.ContactEnum;
import com.xbongbong.saas.enums.business.CustomerManagementEnum;
import com.xbongbong.saas.enums.business.SalesOpportunityEnum;
import com.xbongbong.saas.model.FormConfigModel;
import com.xbongbong.saas.model.IndexTypeModel;
import com.xbongbong.saas.model.PublicGroupModel;
import com.xbongbong.saas.model.PublicGroupSeniorModel;
import com.xbongbong.saas.model.RecheckingRuleModel;
import com.xbongbong.saas.service.PublicGroupService;
import com.xbongbong.sys.domain.entity.UserEntity;
import com.xbongbong.sys.model.DepartmentModel;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import static com.xbongbong.paas.elasticsearch.constant.EsNormalConstant.MINI_MUM_SHOULD_MATCH;
import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.elasticsearch.index.query.QueryBuilders.termsQuery;

/**
 * @description 查重2.0 重复规则帮助类
 * @author yanglei
 * @date 2022/11/9 14:31
 */
@Component
public class RecheckingRuleHelp {
    @Resource
    private IndexTypeModel indexTypeModel;
    @Resource
    private PublicGroupSeniorModel publicGroupSeniorModel;
    @Resource
    private PublicSeniorRuleHelp publicSeniorRuleHelp;
    @Resource
    private ResultShowRuleModel resultShowRuleModel;
    @Resource
    private CommonHelp commonHelp;
    @Resource
    private PublicGroupService publicGroupService;
    @Resource
    private PublicGroupModel publicGroupModel;
    @Resource
    private EsHelper esHelper;
    @Resource
    private PaasProcessNodeTaskService processNodeTaskService;
    @Resource
    private PaasFormExplainModel paasFormExplainModel;
    @Resource
    private PaasFormModel paasFormModel;
    @Resource
    private RecheckingRuleModel recheckingRuleModel;
    @Resource
    private FormConfigModel formConfigModel;
    @Resource
    private DepartmentModel departmentModel;

    /**
     * @description 判断是否是客户、线索、 联系人、 机会的名称或电话字段
     * @author jiangren.li
     * @date 2022/11/9 14:39
     * @return RecheckAttrRulePojo
     */
    public boolean checkNameAndPhone(String attr){
        boolean flag =  Boolean.FALSE;
        try {
            if (Objects.nonNull(attr) && (Objects.equals(attr, StringConstant.NAME) || Objects.equals(attr, StringConstant.PHONE))) {
                flag = Boolean.TRUE;
            }
        } catch (Exception e) {
           return Boolean.FALSE;
        }
        return flag;
    }

    /**
     * @description 判断是否是客户、线索、 联系人、 机会的流水号、成员单选
     * @author jiangren.li
     * @date 2022/11/9 14:39
     * @return RecheckAttrRulePojo
     */
    public boolean checkSerialNoAndUser(Integer fieldType){

        boolean flag =  Boolean.FALSE;
        try {
            if (Objects.nonNull(fieldType) && (Objects.equals(fieldType, FieldTypeEnum.SERIALNO.getType()) || Objects.equals(fieldType, FieldTypeEnum.USER.getType()))) {
                flag = Boolean.TRUE;
            }
        } catch (Exception e) {
            return Boolean.FALSE;
        }
        return flag;
    }

    /**
     * @description 判断是否是客户、线索、 联系人、 机会的查重字段类型
     * @author jiangren.li
     * @date 2022/11/9 14:39
     * @return RecheckAttrRulePojo
     */
    public boolean checkNoRepeatFieldType(Integer fieldType){
        boolean flag =  Boolean.FALSE;
        try {
            if (Objects.nonNull(fieldType) && (Objects.equals(fieldType, FieldTypeEnum.TEXT.getType())
                    || Objects.equals(fieldType, FieldTypeEnum.USER.getType())
                    || Objects.equals(fieldType, FieldTypeEnum.SERIALNO.getType()))) {
                flag = Boolean.TRUE;
            }
        } catch (Exception e) {
            return Boolean.FALSE;
        }
        return flag;
    }

    /**
     * @description 通过业务类型返回具体重复规则,返回集合
     * @author jiangren.li
     * @date 2022/11/9 14:39
     * @return List<RecheckAttrRulePojo>
     */
    public RecheckAttrRulePojo getRecheckAttrRuleByBusinessType(Integer businessType, RecheckFormRulePojo recheckFormRulePojo){
        try {
            List<RecheckAttrRulePojo> recheckAttrRulePojoList = new ArrayList<>();
            XbbRefTypeEnum xbbRefTypeEnum = XbbRefTypeEnum.getByCode(businessType);
            switch (xbbRefTypeEnum){
                case CUSTOMER_MANAGEMENT:
                    recheckAttrRulePojoList = recheckFormRulePojo.getCustomer();
                    break;
                case CLUE:
                    recheckAttrRulePojoList = recheckFormRulePojo.getClue();
                    break;
                case CONTACT:
                    recheckAttrRulePojoList = recheckFormRulePojo.getContact();
                    break;
                case SALES_OPPORTUNITY:
                    recheckAttrRulePojoList = recheckFormRulePojo.getOpportunity();
                    break;
                default:
                    break;
            }

            if (recheckAttrRulePojoList.size() > 0) {
                return recheckAttrRulePojoList.get(0);
            }
        } catch (Exception e) {

        }
        return new RecheckAttrRulePojo();
    }
    /**
     * @description 校验是否要查审批中的数据
     * 未开启工作流、非线索查客户、非线索查联系人、非销售机会
     * @author jiangren.li
     * @date 2022/11/9 14:39
     * @return List<RecheckAttrRulePojo>
     */
    public boolean checkSearchApproval(CheckRepeatToolDTO checkRepeatToolDTO){
        boolean flag =  Boolean.FALSE;
        try {
            if (!checkRepeatToolDTO.getIsOpenWorkflow() &&
                    !checkRepeatToolDTO.getIsClueLinkCustomer() &&
                    !checkRepeatToolDTO.getIsClueLinkContact() &&
                    !Objects.equals(XbbRefTypeEnum.SALES_OPPORTUNITY.getCode(),checkRepeatToolDTO.getBusinessType())
            ) {
                flag = Boolean.TRUE;
            }
        } catch (Exception e) {
            return Boolean.FALSE;
        }
        return flag;
    }

    /**
     * 获得当前登录人有无客户、联系人、线索的菜单权限  false代表没有菜单权限
     *
     * @param
     * @return
     * @throws XbbException
     */
    public boolean checkMenuPermission(Integer businessType, UserVO loginUser) throws XbbException {
        XbbRefTypeEnum xbbRefTypeEnum = XbbRefTypeEnum.getByCode(businessType);
        Set<String> permissionAlias = loginUser.getPermSet();
        boolean permissionFlag = false;
        switch (xbbRefTypeEnum) {
            case CUSTOMER_MANAGEMENT:
                //判断有没有客户的菜单权限
                permissionFlag = permissionAlias.contains(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getAlias());
                break;
            case CONTACT:
                permissionFlag = permissionAlias.contains(XbbRefTypeEnum.CONTACT.getAlias());
                break;
            case CLUE:
                permissionFlag = permissionAlias.contains(XbbRefTypeEnum.CLUE.getAlias());
                break;
        }
        return permissionFlag;
    }

    /**
     * 获取业务查重结果展示字段 (旗舰版可以配置结果集展示)
     *
     * @param
     * @return
     * @throws XbbException
     */
    public List<String> getRecheckResultField(Long firstFormId, CheckRepeatToolDTO checkRepeatToolDTO,Map<String, FieldAttrEntity> explainMap) throws XbbException{
        List<String> resultField = new ArrayList<>();
        Integer feeType = checkRepeatToolDTO.getFeeType();
        if (Objects.equals(PackageTypeEnum.ULTIMATE.getType(), feeType)) {
            ResultShowRuleEntity resultShowRuleEntity = resultShowRuleModel.getByFormId(firstFormId, checkRepeatToolDTO.getCorpid());
            if (Objects.nonNull(resultShowRuleEntity)) {
                resultField = JSONArray.parseArray(resultShowRuleEntity.getResultRules(), String.class);
            } else {
                resultField = getDefaultResultField(checkRepeatToolDTO.getBusinessType(), explainMap);
            }
        } else {
            resultField = getDefaultResultField(checkRepeatToolDTO.getBusinessType(), explainMap);
        }
        return resultField;
    }

    /**
     * 校验登录人获取查重的数据是否在所属分组权限内
     *
     * @throws
     * @return
     * @author lijiangren
     * @date 2022-11-16 17 32
     * @since
     * @version
     */
    public List<Long> getGroupId2CustomerAndClue(Long formId, CheckRepeatToolDTO customerCheckRepeatDTO, List<PaasFormDataEntityExt> entityExtList) throws XbbException {
        String corpid = customerCheckRepeatDTO.getCorpid();
        Integer businessType = customerCheckRepeatDTO.getBusinessType();
        List<Long> dataIdList = new ArrayList<>();
        entityExtList.forEach(item -> {
            dataIdList.add(item.getDataId());
        });

        //如果是超管或者最大数据权限，不需要查询分组
        if (customerCheckRepeatDTO.getLoginUser().isAdminOrBoss() || customerCheckRepeatDTO.getLoginUser().isMaxDataPermission()) {
            return dataIdList;
        }
        if (dataIdList == null || dataIdList.isEmpty()) {
            return new ArrayList<>();
        }

        List<Long> customerIdInGroup = new ArrayList<>();
        UserEntity userEntity = new UserEntity();
        BeanUtil.copyProperties(customerCheckRepeatDTO.getLoginUser(), userEntity);


        if (commonHelp.isPublicPoolSeniorModel(corpid, businessType)) {
            List<PublicGroupSeniorEntity> publicGroupSeniorEntityList = publicGroupSeniorModel.findEntityByStatus(corpid, formId, BasicConstant.ONE);
            //如果该表单下未开启分组直接返回
            if (CollectionsUtil.isEmpty(publicGroupSeniorEntityList)) {
                return dataIdList;
            }

            //过滤出登录人有查看权限的公海分组
            publicGroupSeniorEntityList = publicGroupService.filterGroupSeniorByUser(publicGroupSeniorEntityList, userEntity);

            List groupIdList = new ArrayList();
            for (PublicGroupSeniorEntity publicGroupSeniorEntity : publicGroupSeniorEntityList) {
                groupIdList.add(publicGroupSeniorEntity.getId());
            }

            String groupAttr = CustomerManagementEnum.PUBLIC_GROUP.getAttr();
            if (Objects.equals(businessType,XbbRefTypeEnum.CLUE.getCode())) {
                groupAttr = ClueEnum.PUBLIC_GROUP.getAttr();
            }
            boolean exitsNoPublic = publicGroupSeniorEntityList.stream().filter(item -> Objects.equals(item.getGroupType(), SeniorPublicGroupTypeEnum.NO_PUBLIC_GROUP.getType())).findAny().isPresent();
            for (PaasFormDataEntityExt paasFormDataEntityExt : entityExtList) {
                JSONObject jsonObject = JSON.parseObject(paasFormDataEntityExt.getData().toJSONString());
                String publicGroup = jsonObject.getString(groupAttr);
                if (StringUtil.isNotEmpty(publicGroup)) {
                    if (!groupIdList.contains(Long.valueOf(publicGroup))) {
                        //数据绑定的分组ID 不在有权限的分组ID内，移除操作
                        //考虑分组被删除 绑定的分组ID是已经删除的分组 这个数据应该是数据无分组，判断是否有无分组权限。如果没有无分组权限则进行移除操作
                        if (!exitsNoPublic) {
                            dataIdList.remove(paasFormDataEntityExt.getDataId());
                        }
                    }
                } else {
                    //考虑无分组情况。
                    if (!exitsNoPublic) {
                        dataIdList.remove(paasFormDataEntityExt.getDataId());
                    }
                }
            }
            return dataIdList;

        } else {
            List<PublicGroupEntity> publicGroupEntityList = publicGroupModel.enableListByFormId(customerCheckRepeatDTO.getCorpid(), formId);
            boolean noPublicGroup = false;
            if (!publicGroupEntityList.isEmpty()) {
                //过滤出登录人有查看权限的公海分组
                publicGroupEntityList = publicGroupService.filterGroupByUser(publicGroupEntityList, userEntity);
            } else {
                noPublicGroup = true;
            }

            //拼接分组刷选条件查询
            BoolQueryBuilder boolQueryBuilder = boolQuery();
            boolQueryBuilder.filter(termQuery("corpid.keyword", customerCheckRepeatDTO.getCorpid()));
            boolQueryBuilder.filter(termQuery(StringConstant.DEL, DelEnum.NORMAL.getDel()));
            boolQueryBuilder.filter(termsQuery(FieldTypeEnum.FLOW_STATUS.getAlias(), Arrays.asList(FlowStatusEnum.NOT_NEED_APPROVAL.getType(), FlowStatusEnum.PASS.getType())));
            boolQueryBuilder.filter(termsQuery(FieldTypeEnum.DATAID.getAlias(), dataIdList));
            IndexTypeEnum indexTypeEnum = indexTypeModel.getIndexType(customerCheckRepeatDTO.getCorpid(), businessType, SaasMarkEnum.SAAS.getCode());

            if (noPublicGroup) {
                //关闭所有公海分组
            } else if (publicGroupEntityList.isEmpty()) {
                boolQueryBuilder.filter(termQuery(FieldTypeEnum.DATAID.getAlias(), -1));
            } else {
                for (PublicGroupEntity entity : publicGroupEntityList) {
                    BoolQueryBuilder innerBoolQueryBuilder = boolQuery();
                    List<ConditionsEntityExt> conditionsEntityExtList = entity.getJsonData().toJavaList(ConditionsEntityExt.class);
                    publicSeniorRuleHelp.addressSearchShouldCondition(conditionsEntityExtList);
                    EsUtil.parseCondition(innerBoolQueryBuilder, conditionsEntityExtList, "", customerCheckRepeatDTO.getCorpid(), businessType);
                    innerBoolQueryBuilder.filter(termQuery("formId", entity.getFormId()));
                    boolQueryBuilder.should(innerBoolQueryBuilder);
                }
                boolQueryBuilder.minimumShouldMatch(MINI_MUM_SHOULD_MATCH);
            }
            List<PaasFormDataEntityExt> paasFormDataEntityExtList = esHelper.findByScroll(indexTypeEnum, boolQueryBuilder, PaasFormDataEntityExt.class, Collections.singletonList(FieldTypeEnum.DATAID.getAlias()));
            for (PaasFormDataEntityExt entityExt : paasFormDataEntityExtList) {
                customerIdInGroup.add(entityExt.getDataId());
            }
        }

        //登陆通过分组查看权限过滤出来的数据 or 改表单下没有启用分组直接根据dataIdList再查一次。
        //没有开启分组和没有查看权限的分组是不是同一个道理
        return customerIdInGroup;
    }



    /**
     * 判断数据所在的位置
     *
     * @throws
     * @return
     * @author lijiangren
     * @date 2022-11-16 17 32
     * @since
     * @version
     */
    public String getPositionByBusinessType(Integer businessType, PaasFormDataEntityExt entity) throws XbbException {
        XbbRefTypeEnum xbbRefTypeEnum = XbbRefTypeEnum.getByCode(businessType);
        String position = null;
        switch (xbbRefTypeEnum) {
            case CUSTOMER_MANAGEMENT:
                if (entity.getDel() == 1) {
                   return XbbRefTypeEnum.CUSTOMER_RECYCLE.getName();
                }
                if (Objects.equals(entity.getFlowStatus(), FlowStatusEnum.APPROVAL_PENDING.getType()) || Objects.equals(entity.getFlowStatus(), FlowStatusEnum.IN_APPROVAL.getType())) {
                    return I18nMessageUtil.getMessage(I18nStringConstant.APPROVAL_LIST);
                }
                if (Objects.equals(entity.getData().getInteger(CustomerManagementEnum.IS_PUBLIC.getAttr()), 1)) {
                    return XbbRefTypeEnum.CUSTOMER_PUBLIC.getName();
                }
                return I18nMessageUtil.getMessage(I18nStringConstant.CUSTOMER_LIST);
            case CONTACT:
                if (Objects.equals(entity.getFlowStatus(), FlowStatusEnum.APPROVAL_PENDING.getType()) || Objects.equals(entity.getFlowStatus(), FlowStatusEnum.IN_APPROVAL.getType())) {
                    return I18nMessageUtil.getMessage(I18nStringConstant.APPROVAL_LIST);
                }
                return  I18nMessageUtil.getMessage(I18nStringConstant.CONTACT_LIST);
            case CLUE:
                if (entity.getDel() == 1) {
                    return XbbRefTypeEnum.CLUE_RECYCLE.getName();
                }
                if (Objects.equals(entity.getFlowStatus(), FlowStatusEnum.APPROVAL_PENDING.getType()) || Objects.equals(entity.getFlowStatus(), FlowStatusEnum.IN_APPROVAL.getType())) {
                    return I18nMessageUtil.getMessage(I18nStringConstant.APPROVAL_LIST);
                }
                if (Objects.equals(entity.getData().getInteger(ClueEnum.IS_PUBLIC.getAttr()), 1)) {
                    return  XbbRefTypeEnum.CLUE_PUBLIC.getName();
                }
                return I18nMessageUtil.getMessage(I18nStringConstant.CLUE_LIST);
            case SALES_OPPORTUNITY:
                if (Objects.equals(entity.getFlowStatus(), FlowStatusEnum.APPROVAL_PENDING.getType()) || Objects.equals(entity.getFlowStatus(), FlowStatusEnum.IN_APPROVAL.getType())) {
                    return I18nMessageUtil.getMessage(I18nStringConstant.APPROVAL_LIST);
                }
                return  I18nMessageUtil.getMessage(I18nStringConstant.OPPORTUNITY_LIST);
            default:
                break;
        }
        return position;
    }


    public Integer getSubBusinessType(Integer businessType, PaasFormDataEntityExt entity) throws XbbException {
        XbbRefTypeEnum xbbRefTypeEnum = XbbRefTypeEnum.getByCode(businessType);
        switch (xbbRefTypeEnum) {
            case CUSTOMER_MANAGEMENT:
                if (entity.getDel() == 1) {
                    return XbbRefTypeEnum.CUSTOMER_RECYCLE.getCode();
                }
                if (Objects.equals(entity.getData().getInteger(CustomerManagementEnum.IS_PUBLIC.getAttr()), 1)) {
                    return XbbRefTypeEnum.CUSTOMER_PUBLIC.getCode();
                }
                return XbbRefTypeEnum.CUSTOMER.getCode();
            case CONTACT:
                return  XbbRefTypeEnum.CONTACT.getCode();
            case CLUE:
                if (entity.getDel() == 1) {
                    return XbbRefTypeEnum.CLUE_RECYCLE.getCode();
                }
                if (Objects.equals(entity.getData().getInteger(ClueEnum.IS_PUBLIC.getAttr()), 1)) {
                    return  XbbRefTypeEnum.CLUE_PUBLIC.getCode();
                }
                return XbbRefTypeEnum.ALL_CLUE.getCode();
            case SALES_OPPORTUNITY:
                return  XbbRefTypeEnum.ALL_OPPORTUNITY.getCode();
            default:
                break;
        }
        return XbbRefTypeEnum.UNKNOWN.getCode();
    }


    /**
     * 渲染审批中的数据
     * @return
     * @author lijiangren
     * @date 2022-11-16 20 40
     * @since
     * @version
     */
    public void dealApprovalDataResult(CheckRepeatToolDTO checkRepeatToolDTO, List<Map> dataList, List<String> defaultRestltRule, List<PaasProcessDataEntity> partPaasProcessData, Map<String, FieldAttrEntity> explainMap) throws XbbException {
        for (PaasProcessDataEntity partPaasProcessDate : partPaasProcessData) {
            if (dataList.size() < 10) {
                ProcessNodeTaskGetDTO processNodeTaskGetDTO = new ProcessNodeTaskGetDTO();
                BeanUtil.copyProperties(checkRepeatToolDTO, processNodeTaskGetDTO);
                BeanUtil.copyProperties(partPaasProcessDate, processNodeTaskGetDTO);
                processNodeTaskGetDTO.setProcessTaskId(partPaasProcessDate.getTaskId());
                ProcessNodeTaskGetVO processNodeTaskGetVO = processNodeTaskService.duplicateApprovalDetail(processNodeTaskGetDTO, partPaasProcessDate);
                JSONObject data = processNodeTaskGetVO.getData();
                Map resultMap = new HashMap(defaultRestltRule.size());
                for (String restAttr : defaultRestltRule) {
                    if (Objects.equals(restAttr, CustomerManagementEnum.IS_ARCHIVED.getAttr())) {
                        Object value = Objects.equals(data.getInteger(CustomerManagementEnum.IS_ARCHIVED.getAttr()), 1) ? I18nMessageUtil.getMessage(CommonConstant.YES) : I18nMessageUtil.getMessage(CommonConstant.NO);
                        resultMap.put(restAttr, value);
                    } else if (Objects.equals(restAttr, "position")) {
                        resultMap.put(restAttr, I18nMessageUtil.getMessage(I18nStringConstant.APPROVAL_LIST));
                    } else {
                        dealTimeFormat(explainMap, data, resultMap, restAttr);
                    }
                    resultMap.put("id", null);
                    resultMap.put("del", null);
                    resultMap.put("flowStatus", partPaasProcessDate.getFlowStatus());

                }
                dataList.add(resultMap);
            }
        }
    }

    /**
     * 时间的格式化处理
     * @return
     * @author lijiangren
     * @date 2022-11-16 20 40
     * @since
     * @version
     */
    public void dealTimeFormat(Map<String, FieldAttrEntity> explainMap, JSONObject data, Map resultMap, String attr) {
        //日期和创建时间和更新时间处理
        Object value = data.get(attr);
        FieldAttrEntity fieldAttrEntity = explainMap.get(attr);
        if (Objects.nonNull(fieldAttrEntity)) {
            if (Objects.nonNull(value) && StringUtil.isNotEmpty(value.toString()) && value instanceof Long) {
                if (Objects.equals(fieldAttrEntity.getFieldType(), FieldTypeEnum.DATETIME.getType())) {
                    String dateType = fieldAttrEntity.getDateType();
                    value = DateTimeUtil.getStringEpochSecond(Long.valueOf(value.toString()), new SimpleDateFormat(dateType));
                } else if (Objects.equals(fieldAttrEntity.getFieldType(), FieldTypeEnum.ADDTIME.getType()) || Objects.equals(fieldAttrEntity.getFieldType(), FieldTypeEnum.UPDATETIME.getType())) {
                    value = DateTimeUtil.getStringEpochSecond(Long.valueOf(value.toString()), DateTimeUtil.SDF);
                }
            }
        }
        resultMap.put(attr, value);
    }


    /**
     * 获取业务查重结果展示默认字段
     *
     * @param
     * @return
     * @throws XbbException
     */
    private List<String> getDefaultResultField(Integer businessType, Map<String, FieldAttrEntity> explainMap) {
        List<JSONObject> checkRepeatHead = new ArrayList<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        //代表第一次点击，给与默认展示字段
        XbbRefTypeEnum xbbRefTypeEnum = XbbRefTypeEnum.getByCode(businessType);
        switch (xbbRefTypeEnum) {
            case CUSTOMER_MANAGEMENT:
                checkRepeatHead = CustomerManagementEnum.getCheckRepeatHead();
                break;
            case CONTACT:
                checkRepeatHead = ContactEnum.getCheckRepeatHead();
                break;
            case CLUE:
                checkRepeatHead = ClueEnum.getCheckRepeatHead();
                break;
            case SALES_OPPORTUNITY:
                checkRepeatHead = SalesOpportunityEnum.getCheckRepeatHead();
                break;
            default:
                break;
        }
        //判断默认字段中在当前表单解释中是否有处于未启用或回收站的数据
        List<String> newResultShowRulePojos = new ArrayList<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        List<ResultShowRulePojo> resultShowRulePojos = JSONArray.parseArray(String.valueOf(checkRepeatHead)).toJavaList(ResultShowRulePojo.class);
        for (ResultShowRulePojo resultShowRulePojo : resultShowRulePojos) {
            boolean ruleFlag = Objects.equals(resultShowRulePojo.getLabel(), I18nMessageUtil.getMessage(I18nStringConstant.LOCATION)) ||
                    Objects.equals(resultShowRulePojo.getLabel(), I18nMessageUtil.getMessage(CommonConstant.OPERATE));
            if (StringUtil.isNotEmpty(resultShowRulePojo.getAttr())) {
                FieldAttrEntity fieldAttrEntity = explainMap.get(resultShowRulePojo.getAttr());
                if (Objects.nonNull(fieldAttrEntity)) {
                    //判断是否处于未启用或回收站
                    Integer isOpen = fieldAttrEntity.getIsOpen();
                    //isOpen为0代表不启用，为1代表启用  为2代表是在回收站中
                    boolean flag = Objects.nonNull(isOpen) && (Objects.equals(BasicConstant.ZERO, isOpen) || Objects.equals(BasicConstant.TWO, isOpen));
                    if (!flag) {
                        newResultShowRulePojos.add(resultShowRulePojo.getAttr());
                    }
                }
            } else if (Objects.isNull(resultShowRulePojo.getAttr()) && ruleFlag) {
                newResultShowRulePojos.add(resultShowRulePojo.getProp());
            }
        }
        return newResultShowRulePojos;
    }



    /**
     * 获取查重字段
     * @param seniorReCheckSearchDTO
     * @return
     * @throws XbbException
     */
    public List<RepeatSearchFieldPojo> packageSearchFieldByBusinessType(SeniorReCheckSearchDTO seniorReCheckSearchDTO) throws XbbException {
        Integer businessType = seniorReCheckSearchDTO.getBusinessType();
        if ((seniorReCheckSearchDTO.getIsClueLinkContact() || seniorReCheckSearchDTO.getIsClueLinkCustomer() ) &&
                !Objects.equals(PackageTypeEnum.STANDARD.getType(), seniorReCheckSearchDTO.getFeeType())) {
            //只有旗舰版、高级版有联合判重
           if (Objects.equals(businessType,XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode())) {
               return packageRecheckSearchFieldByLinkCustomer(seniorReCheckSearchDTO);
           } else {
               return packageRecheckSearchFieldByLinkContact(seniorReCheckSearchDTO);
           }
        } else {
            return packageRecheckSearchField(seniorReCheckSearchDTO);
        }
    }

    /**
     * 校验名称字段是否全局判重
     * @param  formId,  businessType,  corpid
     * @return
     * @throws XbbException
     */
    public RecheckAttrRulePojo checkNameRecheckType(Long formId, Integer businessType, String corpid) throws XbbException {
        RecheckingRuleEntity recheckingRule = recheckingRuleModel.getRuleListByFormId(corpid, formId, businessType);
        if (Objects.nonNull(recheckingRule)) {
            String checkToolRule = recheckingRule.getCheckToolRule();
            List<RecheckFormRulePojo> recheckFormRuleList = JSONArray.parseArray(checkToolRule, RecheckFormRulePojo.class);
            for (RecheckFormRulePojo recheckFormRulePojo : recheckFormRuleList) {
                RecheckAttrRulePojo recheckAttrRule = getRecheckAttrRuleByBusinessType(businessType,recheckFormRulePojo);
                if (Objects.nonNull(recheckAttrRule) && Objects.equals(StringConstant.NAME,recheckAttrRule.getAttr())) {
                   return recheckAttrRule;
                }
            }
        }
        return null;
    }


    /**
     * 根据传入的查重字段查询重复规则配置表封装查重字段的List
     * @return
     * @author lijiangren
     * @date 2022-11-16 20 40
     * @since
     * @version
     */
    public List<RepeatSearchFieldPojo> packageRecheckSearchField(SeniorReCheckSearchDTO seniorReCheckSearchDTO) throws XbbException {
        String corpid = seniorReCheckSearchDTO.getCorpid();
        Integer businessType = seniorReCheckSearchDTO.getBusinessType();
        Long formId = seniorReCheckSearchDTO.getFormId();
        List<SeniorCheckRepeatSearchPojo> searchList = seniorReCheckSearchDTO.getSearchList();
        List<RepeatSearchFieldPojo> packageSearchFieldList = new ArrayList<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        RecheckingRuleEntity recheckingRule = recheckingRuleModel.getRuleListByFormId(corpid, formId, businessType);
        String checkToolRule = recheckingRule.getCheckToolRule();
        List<RecheckFormRulePojo> recheckFormRuleList = JSONArray.parseArray(checkToolRule, RecheckFormRulePojo.class);

        for (SeniorCheckRepeatSearchPojo seniorCheckRepeatSearchPojo : searchList) {
            RepeatSearchFieldPojo repeatSearchFieldPojo = new RepeatSearchFieldPojo();
            repeatSearchFieldPojo.setAttr(seniorCheckRepeatSearchPojo.getAttr());
            repeatSearchFieldPojo.setFormId(formId);
            repeatSearchFieldPojo.setValue(seniorCheckRepeatSearchPojo.getValue());
            String attr = seniorCheckRepeatSearchPojo.getAttr();
            for (RecheckFormRulePojo recheckFormRulePojo : recheckFormRuleList) {
                RecheckAttrRulePojo recheckAttrRulePojo = getRecheckAttrRuleByBusinessType(businessType,recheckFormRulePojo);
                if ( Objects.nonNull(recheckAttrRulePojo) && Objects.equals(attr,recheckAttrRulePojo.getAttr())) {
                    if (Objects.equals(recheckAttrRulePojo.getIsAll(), BasicConstant.ZERO)) {
                        repeatSearchFieldPojo.setMatchWay(recheckAttrRulePojo.getMatchWay());
                        packageSearchFieldList.add(repeatSearchFieldPojo);
                    } else {
                        //全局判重，需要考虑是否是自定义字段
                        PaasFormExplainEntity paasFormExplainEntity = paasFormExplainModel.getByFormId(formId, corpid);
                        Map<String, FieldAttrEntity> allFormExplainMap = ExplainUtil.getAllSubFormExplainMap(paasFormExplainEntity.getExplains());
                        FieldAttrEntity fieldEntity = allFormExplainMap.get(recheckAttrRulePojo.getAttr());
                        if (Objects.nonNull(fieldEntity)) {
                            if (Objects.equals(fieldEntity.getIsRedundant(),BasicConstant.ONE)){
                                //自定义
                                //本模版也需要查
                                repeatSearchFieldPojo.setMatchWay(recheckAttrRulePojo.getMatchWay());
                                packageSearchFieldList.add(repeatSearchFieldPojo);
                                List<CustomRecheckRulePojo> customRecheckRules = fieldEntity.getCustomRecheckRules();
                                if (CollectionsUtil.isNotEmpty(customRecheckRules)) {
                                    for (CustomRecheckRulePojo customRecheckRule : customRecheckRules) {
                                        RepeatSearchFieldPojo repeatSearchField = new RepeatSearchFieldPojo();
                                        repeatSearchField.setAttr(customRecheckRule.getAttr());
                                        repeatSearchField.setMatchWay(recheckAttrRulePojo.getMatchWay());
                                        repeatSearchField.setFormId(customRecheckRule.getFormId());
                                        repeatSearchField.setValue(seniorCheckRepeatSearchPojo.getValue());
                                        packageSearchFieldList.add(repeatSearchField);
                                    }
                                }
                            } else {
                                List<PaasFormEntityExt> enableFormList = paasFormModel.getFormListDistributor(corpid, businessType, BasicConstant.ZERO);
                                for (PaasFormEntityExt paasFormEntityExt : enableFormList) {
                                    RepeatSearchFieldPojo repeatSearchField = new RepeatSearchFieldPojo();
                                    repeatSearchField.setAttr(attr);
                                    repeatSearchField.setMatchWay(recheckAttrRulePojo.getMatchWay());
                                    repeatSearchField.setFormId(paasFormEntityExt.getId());
                                    repeatSearchField.setValue(seniorCheckRepeatSearchPojo.getValue());
                                    packageSearchFieldList.add(repeatSearchField);
                                }
                            }
                        }
                    }
                }
            }
        }

        return packageSearchFieldList;

    }

    /**
     * 线索联合客户查重字段封装
     * @return
     * @author lijiangren
     * @date 2022-11-16 20 40
     * @since
     * @version
     */
    public List<RepeatSearchFieldPojo> packageRecheckSearchFieldByLinkCustomer(SeniorReCheckSearchDTO seniorReCheckSearchDTO) throws XbbException {
        String corpid = seniorReCheckSearchDTO.getCorpid();
        Integer businessType = seniorReCheckSearchDTO.getBusinessType();
        Long formId = seniorReCheckSearchDTO.getFormId();
        List<SeniorCheckRepeatSearchPojo> searchList = seniorReCheckSearchDTO.getSearchList();
        List<RepeatSearchFieldPojo> packageSearchFieldList = new ArrayList<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        RecheckingRuleEntity recheckingRule = recheckingRuleModel.getRuleListByFormId(corpid, formId, XbbRefTypeEnum.CLUE.getCode());
        String checkToolRule = recheckingRule.getCheckToolRule();
        List<RecheckFormRulePojo> recheckFormRuleList = JSONArray.parseArray(checkToolRule, RecheckFormRulePojo.class);
        for (SeniorCheckRepeatSearchPojo seniorCheckRepeatSearchPojo : searchList) {
            String attr = seniorCheckRepeatSearchPojo.getAttr();
            if (Objects.equals(PackageTypeEnum.ADVANCED.getType(), seniorReCheckSearchDTO.getFeeType())) {
                //高级版：只需要查电话和名称字段
                if (!(Objects.equals(attr,StringConstant.NAME) || Objects.equals(attr,StringConstant.PHONE))) {
                    continue;
                }
            }
            for (RecheckFormRulePojo recheckFormRulePojo : recheckFormRuleList) {
                List<RecheckAttrRulePojo> customerAttrRule = recheckFormRulePojo.getCustomer();
                if (CollectionsUtil.isNotEmpty(customerAttrRule)) {
                    RecheckAttrRulePojo recheckAttrRulePojo = customerAttrRule.get(0);
                    if (Objects.equals(attr,recheckAttrRulePojo.getAttr())) {
                        if (Objects.equals(recheckAttrRulePojo.getIsAll(), BasicConstant.ZERO)) {
                            RepeatSearchFieldPojo repeatSearchFieldPojo = new RepeatSearchFieldPojo();
                            repeatSearchFieldPojo.setAttr(recheckAttrRulePojo.getLinkAttr());
                            repeatSearchFieldPojo.setFormId(recheckAttrRulePojo.getLinkFormId());
                            repeatSearchFieldPojo.setMatchWay(recheckAttrRulePojo.getMatchWay());
                            repeatSearchFieldPojo.setValue(seniorCheckRepeatSearchPojo.getValue());
                            packageSearchFieldList.add(repeatSearchFieldPojo);
                        } else {
                            //全局判重
                            List<PaasFormEntityExt> enableFormList = paasFormModel.getFormListDistributor(corpid, businessType, BasicConstant.ZERO);
                            for (PaasFormEntityExt paasFormEntityExt : enableFormList) {
                                RepeatSearchFieldPojo repeatSearchField = new RepeatSearchFieldPojo();
                                repeatSearchField.setAttr(recheckAttrRulePojo.getLinkAttr());
                                repeatSearchField.setMatchWay(recheckAttrRulePojo.getMatchWay());
                                repeatSearchField.setFormId(paasFormEntityExt.getId());
                                repeatSearchField.setValue(seniorCheckRepeatSearchPojo.getValue());
                                packageSearchFieldList.add(repeatSearchField);
                            }
                        }

                    }
                }
            }
        }

        return  packageSearchFieldList;

    }

    /**
     * 线索联合联系人查重字段封装
     * @return
     * @author lijiangren
     * @date 2022-11-16 20 40
     * @since
     * @version
     */
    public List<RepeatSearchFieldPojo> packageRecheckSearchFieldByLinkContact(SeniorReCheckSearchDTO seniorReCheckSearchDTO) throws XbbException {
        String corpid = seniorReCheckSearchDTO.getCorpid();
        Long formId = seniorReCheckSearchDTO.getFormId();
        List<SeniorCheckRepeatSearchPojo> searchList = seniorReCheckSearchDTO.getSearchList();
        List<RepeatSearchFieldPojo> packageSearchFieldList = new ArrayList<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        RecheckingRuleEntity recheckingRule = recheckingRuleModel.getRuleListByFormId(corpid, formId, XbbRefTypeEnum.CLUE.getCode());
        String checkToolRule = recheckingRule.getCheckToolRule();
        List<RecheckFormRulePojo> recheckFormRuleList = JSONArray.parseArray(checkToolRule, RecheckFormRulePojo.class);
        //获取一下联系人模板id,防止linkForm为空或者为0
        Long contactFormId = paasFormModel.getFormIdByBusinessType(corpid,XbbRefTypeEnum.CONTACT.getCode());
        for (SeniorCheckRepeatSearchPojo seniorCheckRepeatSearchPojo : searchList) {
            String attr = seniorCheckRepeatSearchPojo.getAttr();
            if (Objects.equals(PackageTypeEnum.ADVANCED.getType(), seniorReCheckSearchDTO.getFeeType())) {
                //高级版：只需要查电话和名称字段
                if (!(Objects.equals(attr,StringConstant.NAME) || Objects.equals(attr,StringConstant.PHONE))) {
                    continue;
                }
            }
            for (RecheckFormRulePojo recheckFormRulePojo : recheckFormRuleList) {
                List<RecheckAttrRulePojo> customerAttrRule = recheckFormRulePojo.getContact();
                if (CollectionsUtil.isNotEmpty(customerAttrRule)) {
                    RecheckAttrRulePojo recheckAttrRulePojo = customerAttrRule.get(0);
                    Long linkFormId = recheckAttrRulePojo.getLinkFormId();
                    linkFormId = Objects.isNull(linkFormId) || Objects.equals(linkFormId,BasicConstant.ZERO_LONG) ? contactFormId : recheckAttrRulePojo.getLinkFormId();
                    if (Objects.equals(attr,recheckAttrRulePojo.getAttr())) {
                        RepeatSearchFieldPojo repeatSearchFieldPojo = new RepeatSearchFieldPojo();
                        repeatSearchFieldPojo.setAttr(recheckAttrRulePojo.getLinkAttr());
                        repeatSearchFieldPojo.setFormId(linkFormId);
                        repeatSearchFieldPojo.setMatchWay(recheckAttrRulePojo.getMatchWay());
                        repeatSearchFieldPojo.setValue(seniorCheckRepeatSearchPojo.getValue());
                        packageSearchFieldList.add(repeatSearchFieldPojo);
                    }
                }
            }
        }

        return  packageSearchFieldList;
    }

    /**
     * @description 更新名称和电话字段到formConfig表
     * @author yanglei
     * @date 2022/11/24 20:44
     * @param isAll 是否全部模板
     * @param formConfigEntity
     * @param updateConfig 需要更新的字段配置
     * @param corpid 公司id
     * @param menuId 菜单id
     * @param businessType 业务类型
     */
    public void updateNamePhoneToFormConfig(Integer isAll, FormConfigEntity formConfigEntity,String updateConfig,String corpid,Long menuId,Integer businessType) throws XbbException {
        if (formConfigEntity == null) {
            // 若是第一次设置全局，将其余表单配置同步到表单配置表
            if (Objects.equals(isAll,BasicConstant.ONE)) {
                formConfigModel.insertRepeatType(corpid, menuId, updateConfig, businessType);
            }
        } else {
            // 1. 从不判重或模板内判重改为全局判重(即现在是全局状态)，同步更改其他表单
            // 2. 从全局判重改为不判重或模板内判重(即以前是全局状态)，同步更改其他表单
            if (Objects.isNull(isAll) && Objects.equals(formConfigEntity.getConfigValue(), RepeatTypeEnum.REPEAT_ALL.getType().toString())){
                //说明取消勾选
                formConfigModel.updateAllRepeatType(corpid, updateConfig, RepeatTypeEnum.REPEAT_CANCEL.getType().toString());
            }else if (Objects.equals(isAll, BasicConstant.ONE)){
                //所有模板改成全局判重
                formConfigModel.updateAllRepeatType(corpid, updateConfig, RepeatTypeEnum.REPEAT_ALL.getType().toString());
            }else if (Objects.equals(isAll, BasicConstant.ZERO) && Objects.equals(formConfigEntity.getConfigValue(), RepeatTypeEnum.REPEAT_ALL.getType().toString())) {
                formConfigModel.updateAllRepeatType(corpid, updateConfig, RepeatTypeEnum.REPEAT_SINGLE.getType().toString());
            } else if(Objects.equals(formConfigEntity.getConfigValue(), RepeatTypeEnum.REPEAT_SINGLE.getType().toString()) || Objects.equals(formConfigEntity.getConfigValue(), RepeatTypeEnum.REPEAT_CANCEL.getType().toString())) {
                // 3. 其余情况只更改自己
                if (Objects.equals(isAll, BasicConstant.ZERO)){
                    formConfigEntity.setConfigValue(RepeatTypeEnum.REPEAT_SINGLE.getType().toString());
                }else {
                    formConfigEntity.setConfigValue(RepeatTypeEnum.REPEAT_CANCEL.getType().toString());
                }
                formConfigEntity.setUpdateTime(DateTimeUtil.getInt());
                try {
                    formConfigModel.update(formConfigEntity);
                } catch (Exception e) {
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
                }
            }
        }
    }

    /**
     * 校验当前用户使用有使用表单的权限
     * @param paasFormEntityExt
     * @param loginUser
     * @return false：无表单使用权限，true：有表单使用权限
     */
    public boolean validatePermission(PaasFormEntityExt paasFormEntityExt, UserVO loginUser) {
        List<OptionalRangeEntity> permissionList = null;
        try {
            permissionList = JSON.parseArray(paasFormEntityExt.getPermission(),
                    OptionalRangeEntity.class);
        } catch (Exception e) {

        }
        permissionList = permissionList == null ? new ArrayList<>() : permissionList;
        if (permissionList.isEmpty()) {
            return true ;
        }
        //是否包含在规则中
        boolean flag = false;
        List<Long> depIdSet = new ArrayList<>();
        for (OptionalRangeEntity optionalRangeEntity : permissionList) {
            String property = optionalRangeEntity.getProperty();
            String id = optionalRangeEntity.getId();

            if (Objects.equals(property, OptionalRangeEnum.DEPT.getValue())){
                //部门判断,先将所有部门id置入depIdSet，再获取所有子部门判断
                Long departmentId = StringUtil.StringToLong(id, -1L);
                depIdSet.add(departmentId);
                continue;
            } else if (Objects.equals(property, OptionalRangeEnum.ROLE.getValue())){
                //角色判断
                String roleIds = loginUser.getRoleIds();
                String roleId = "|" + id + "|";
                //所属角色在设置角色中
                if (roleIds.indexOf(roleId) > -1) {
                    flag = true;
                    break;
                }
            } else if (Objects.equals(property, OptionalRangeEnum.USER.getValue())){
                //员工判断
                String userId = loginUser.getUserId();
                //所属用户在设置用户中
                if (Objects.equals(userId, id)) {
                    flag = true;
                    break;
                }
            }
        }

        String department = loginUser.getDepartment();
        List<Long> departmentIdList = JSON.parseArray(department, Long.class);

        //所有有权限的部门
        List<Long> allDepIdList = new ArrayList<>();
        List<Long> subDepIdList = departmentModel.getSubDepIdList(loginUser.getCorpid(), depIdSet);
        allDepIdList.addAll(subDepIdList);
        allDepIdList.addAll(depIdSet);

        //与用户所属部门取交集
        allDepIdList.retainAll(departmentIdList);
        if (!allDepIdList.isEmpty()) {
            flag = true;
        }
        return flag;
    }

    /**
     * @description 获取重复规则中字段和匹配范围的map
     * @author yanglei
     * @date 2022/12/16 11:03
     * @param noRepeatRuleList 规则
     * @param businessType 业务类型
     * @return Map<Integer>
     */
    public Map<String,Integer> getAttrToIsAllMap(List<RecheckFormRulePojo> noRepeatRuleList,Integer businessType){
        XbbRefTypeEnum xbbRefTypeEnum = XbbRefTypeEnum.getByCode(businessType);
        Map<String,Integer> attrIsAllMap = new HashMap<>();
        if(CollectionsUtil.isNotEmpty(noRepeatRuleList)){
            //1、获取配置了新建不允许重复规则的字段列表和是否全部模板
            for (RecheckFormRulePojo formRulePojo : noRepeatRuleList) {
                switch (xbbRefTypeEnum){
                    case CUSTOMER_MANAGEMENT:
                        List<RecheckAttrRulePojo> customer = formRulePojo.getCustomer();
                        if (CollectionsUtil.isNotEmpty(customer)){
                            attrIsAllMap.put(customer.get(0).getAttr(),customer.get(0).getIsAll());
                        }
                        break;
                    case CLUE:
                        List<RecheckAttrRulePojo> clue = formRulePojo.getClue();
                        if (CollectionsUtil.isNotEmpty(formRulePojo.getClue())){
                            attrIsAllMap.put(clue.get(0).getAttr(),clue.get(0).getIsAll());
                        }
                        break;
                    case CONTACT:
                        List<RecheckAttrRulePojo> contact = formRulePojo.getContact();
                        if (CollectionsUtil.isNotEmpty(formRulePojo.getContact())){
                            attrIsAllMap.put(contact.get(0).getAttr(),contact.get(0).getIsAll());
                        }
                        break;
                    case SALES_OPPORTUNITY:
                        List<RecheckAttrRulePojo> opportunity = formRulePojo.getOpportunity();
                        if (CollectionsUtil.isNotEmpty(formRulePojo.getOpportunity())){
                            attrIsAllMap.put(opportunity.get(0).getAttr(),opportunity.get(0).getIsAll());
                        }
                        break;
                    default:
                        break;
                }
            }
        }
        return attrIsAllMap;
    }

}
